package com.example.enterprise

import android.os.Bundle
import androidx.activity.viewModels

import androidx.appcompat.app.AppCompatActivity
import androidx.core.view.ViewCompat
import androidx.core.view.WindowInsetsCompat
import com.alibaba.android.arouter.facade.annotation.Autowired
import com.alibaba.android.arouter.facade.annotation.Route
import com.alibaba.android.arouter.launcher.ARouter
import com.blankj.utilcode.util.ToastUtils
import com.example.common.view.view.BaseMvvmActivity
import com.example.enterprise.databinding.ActivityMerchantXiangBinding
import com.example.enterprise.vm.EnterpriseViewModel
import com.example.enterprise.vm.MerchantViewModel
import dagger.hilt.android.AndroidEntryPoint

@AndroidEntryPoint
@Route(path="/enterprise/MerchantXiangActivity")
class MerchantXiangActivity : BaseMvvmActivity<ActivityMerchantXiangBinding>() {
    override fun getLayoutId(): Int=R.layout.activity_merchant_xiang
    @Autowired
    @JvmField
    var merchanId:Int=0

    val merchantViewModel:MerchantViewModel by viewModels()
    override fun initView() {
        super.initView()
        ARouter.getInstance().inject(this)
        //返回
        mDataBinding.enterpriseBack.setOnClickListener {
            finish()
        }
        merchantViewModel.getMerchantById(merchanId)
        merchantViewModel.mSuccessLiveData.observe(this){
            it.data.forEach {
                mDataBinding.applicationNumber.text=it.applicationNumber
                mDataBinding.enterpriseName.text=it.enterpriseName
                mDataBinding.peopleName.text=it.contactName
                mDataBinding.merchantTime.text=it.entryTime
                mDataBinding.applicationArea.text=it.applicationArea.toString()+"m²"
                mDataBinding.applicationCount.text=it.entryPersonnel.toString()+"人"
                mDataBinding.applicationTime.text=it.entryTime
                mDataBinding.status.text=it.status
                if(it.status=="新建"){
                    mDataBinding.square1.setBackgroundColor(getResources().getColor(R. color.color_hui))
                    mDataBinding.circle2.setBackgroundColor(getResources().getColor(R. color.color_hui))
                    mDataBinding.square2.setBackgroundColor(getResources().getColor(R. color.color_hui))
                    mDataBinding.circle23.setBackgroundColor(getResources().getColor(R. color.color_hui))
                }else if(it.status=="待审核"){
                    mDataBinding.square2.setBackgroundColor(getResources().getColor(R. color.color_hui))
                    mDataBinding.circle23.setBackgroundColor(getResources().getColor(R. color.color_hui))
                    mDataBinding.text2.setTextColor(getResources().getColor(R. color.color_hui))
                    mDataBinding.text1.text="待审核"
                    mDataBinding.entryTime.text=it.entryTime
                    mDataBinding.enterName.text="发起人(${it.contactName})"
                }else if(it.status=="已审核"){
                    mDataBinding.text1.text="待审核"
                    mDataBinding.entryTime.text=it.entryTime
                    mDataBinding.enterName.text="发起人(${it.contactName})"
                    mDataBinding.text2.text="审核通过"
                }else{
                    mDataBinding.text1.text="待审核"
                    mDataBinding.entryTime.text=it.entryTime
                    mDataBinding.enterName.text="发起人(${it.contactName})"
                    mDataBinding.text2.text="已驳回"
                }
            }

        }
        merchantViewModel.mErrorLiveData.observe(this){
            ToastUtils.showLong(it)
        }
    }

}